package com.whxy02.tolearn.app.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Tags;
import com.whxy02.tolearn.app.dao.TagsDao;
import com.whxy02.tolearn.app.service.TagsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TagsServiceImpl implements TagsService {

    private QueryWrapper<Tags> wrapper=new QueryWrapper<>();

    @Resource
    TagsDao tagsDao;

    @Override
    public List<Tags> getAll() throws Exception {
        return tagsDao.selectList(null);
    }

    @Override
    public Tags getById(Integer id) throws Exception {
        return tagsDao.selectById(id);
    }

    @Override
    public int save(Tags tags) throws Exception {
        return tagsDao.insert(tags);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return tagsDao.deleteById(id);
    }

    @Override
    public int change(Tags tags) throws Exception {
        return tagsDao.updateById(tags);
    }

    @Override
    public List<Tags> getBySubjectId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("subject_id",id);
        return tagsDao.selectList(wrapper);
    }

    @Override
    public Tags getByTagsName(String tagsName) throws Exception {
        wrapper.clear();
        wrapper.eq("tags_name",tagsName);
        return tagsDao.selectOne(wrapper);
    }

    @Override
    public Tags getByTagsAndSubject(String tagsName, Integer subjectId) throws Exception {
        wrapper.clear();
        wrapper.eq("tags_name",tagsName).eq("subject_id",subjectId);
        return tagsDao.selectOne(wrapper);
    }
}
